//
//  SEDiseaseView.m
//  kuaiyi
//
//  Created by Alphts on 16/7/7.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "SEDiseaseView.h"

@interface SEDiseaseView ()

@property (nonatomic, weak) UITextField *tf;

@property (nonatomic, weak) UIImageView *iv_accessory;

@property (nonatomic, weak) UIImageView *iv_line;

@end

@implementation SEDiseaseView

- (instancetype)initWithPlaceholder:(NSString *)placeholder{
    if (self = [super init]) {
        [self setupUIWith:placeholder];
    }
    return self;
}


- (void)setupUIWith:(NSString *)placeholder{
    
    self.backgroundColor = [UIColor whiteColor];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [self addGestureRecognizer:tap];
    
    UITextField *tf = [[UITextField alloc] init];
    self.tf = tf;
    tf.font = FONT(16);
    tf.userInteractionEnabled = NO;
    tf.placeholder = placeholder;
    [self addSubview:tf];
    
    UIImageView *iv_line = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_img_line.png"]];
    self.iv_line = iv_line;
    [self addSubview:iv_line];
    
    UIImageView *iv_accessory = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_button_input_blue.png"]];
    self.iv_accessory = iv_accessory;
    [iv_accessory sizeToFit];
    [self addSubview:iv_accessory];
    
}

- (void)tap:(UITapGestureRecognizer *)tap{
    if (self.accessoryBlock) {
        self.accessoryBlock();
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.iv_accessory makeConstraints:^(MASConstraintMaker *make) {
       
        make.trailing.equalTo(self).offset(-20);
        make.centerY.equalTo(self);
        make.width.equalTo(11);
        make.height.equalTo(18);
    }];

    [self.iv_line makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.iv_accessory.leading).offset(-20);
        make.width.equalTo(1);
        make.top.equalTo(self).offset(7);
        make.centerY.equalTo(self);
    }];
    
    [self.tf makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(self);
        make.leading.equalTo(self).offset(10);
        make.trailing.equalTo(self.iv_line.leading).offset(-20);
    }];

}

- (void)setMessage:(NSString *)message{
    _message = message;
    
    self.tf.text = message;

}


@end
